package com.yurun.controller.admin;

import com.yurun.entity.Category;
import com.yurun.model.vo.Result;
import com.yurun.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class CategoryAdminController {
    @Autowired
    CategoryService categoryService;
    /**
     * @Description: 后台-添加分类
     * @Param: category
     * @return: void
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @PostMapping("/category")
    public void addCategory(@RequestBody Category category){
        categoryService.addCategory(category);
    }
    /**
     * @Description: 后台-通过ID-删除分类
     * @Param: id
     * @return: void
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @DeleteMapping("/category/id")
    public void deleteCategoryById(@RequestParam Long id){
        categoryService.deleteCategoryById(id);
    }
    /**
     * @Description: 后台-更新分类
     * @Param: category
     * @return: void
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @PutMapping("/category")
    public void updatecategory(@RequestBody Category category){
        categoryService.updateCategory(category);
    }
    /**
     * @Description: 后台-获取分类列表
     * @Param:
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @GetMapping("/category")
    public Result getCategoryList(){
        List<Category> object=categoryService.getCategoryList();
        return Result.ok("查询类别列表成功",object);
    }
}
